#define _LED_MODULE_

#include "osObjects.h"
#include "pincfg.h"
#include "ledctr.h"
#include "rtctime.h"
#include "dataproc.h"
#include "pulse.h"

const uint8_t AsciiCode[] =
    {
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x00,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        //0   1     2     3     4     5     6     7     8     9      A    B     C      D    E     F
        0x3f,
        0x06,
        0x5b,
        0x4f,
        0x66,
        0x6d,
        0x7d,
        0x07,
        0x7f,
        0x6f,
        0x77,
        0x7c,
        0x39,
        0x5e,
        0x79,
        0x71,
        //@   A     B     C     D     E     F     G     H     I     J     K     L     M     N     O
        0x40,
        0x77,
        0x7c,
        0x39,
        0x5e,
        0x79,
        0x71,
        0x3D,
        0x76,
        0x30,
        0x0E,
        0x7A,
        0x38,
        0x55,
        0x37,
        0x3f,
        //P   Q     R     S     T     U     V     W     X     Y     Z
        0x73,
        0x67,
        0x77,
        0x6d,
        0x31,
        0x3E,
        0x3E,
        0x6A,
        0x76,
        0x6E,
        0x5b,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
        //.   a     b     c     d     e     f     g     h     i     j     k     l     m     n     o
        0x80,
        0x77,
        0x7c,
        0x58,
        0x5e,
        0x7B,
        0x71,
        0x6f,
        0x74,
        0x30,
        0x0E,
        0x7A,
        0x38,
        0x55,
        0x54,
        0x5C,
        //p   q     r     s     t     u     v     w     x     y     z
        0x73,
        0x67,
        0x50,
        0x6d,
        0x78,
        0x1C,
        0x1C,
        0x6A,
        0x76,
        0x6E,
        0x5b,
        0x40,
        0x40,
        0x40,
        0x40,
        0x40,
};

extern uint32_t uTick;
extern uint32_t IdleTaskCntH;
uint8_t LedBuff[4];
uint32_t LedCnt = 0;
uint8_t databuff[6];
timer_pulse_type led_pulse;

/*****************************************************************************//*!
*
* @brief   led task.
*     
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void LedCtrTask(void *argument)
{
    OS_ERR      err;
    
    pulse_init(&led_pulse, uTick);
    
    for(;;){
        OSTimeDly(50u , OS_OPT_TIME_PERIODIC, &err);
        if (led_pulse.bPulse_1s)
        {
            LedCnt++;
            Uint16ToAscii(LedCnt, 3, databuff);

            LedBuff[0] = AsciiCode[databuff[0]];
            LedBuff[1] = AsciiCode[databuff[1]];
            LedBuff[2] = AsciiCode[databuff[2]];
            LedBuff[3] = AsciiCode[databuff[3]];
        }
        else if(led_pulse.bPulse_500ms && LedCnt)
        {
            Uint16ToAscii(IdleTaskCntH/LedCnt, 3, databuff);

            LedBuff[0] = AsciiCode[databuff[0]];
            LedBuff[1] = AsciiCode[databuff[1]]|0x80;
            LedBuff[2] = AsciiCode[databuff[2]];
            LedBuff[3] = AsciiCode[databuff[3]]; 
        }
    }
}